﻿@using System.Web.Mvc.Html
@using ZBJF.Warranty.BLL
@using ZBJF.Warranty.Common.Enums
@using ZBJF.Warranty.WebProvider
@using ZBJF.Warranty.WebProvider.AdminPemission
@model List<ZBJF.Warranty.Model.RoleToPageToAction>
@{
    ViewBag.Title = "角色授权";
    int roleID = 0;
    if (!int.TryParse(Request["RoleID"], out roleID))
    {
        <text>没有找到该用户信息</text>;
        return;
    }
    var role = ServiceFactory.SystemRoleServiceInstance.LoadByID(roleID);
    var pageToActionIDs = Model.Select(o => o.PageToActionID).ToList().Aggregate(string.Empty, (c, d) => c + ',' + d).Trim(',');
}
<style type="text/css">
    .table td {
        padding: 0 5px !important;
        height: 20px !important;
        line-height: 20px !important;
    }
</style>
@{
    <div class="control-group">
        <h4>角色:@role.RoleName</h4>
    </div>
    <div>
        <h4>已授权:</h4>
        <div class="controls">
            <form id="roleToPageToActionSearchForm" class="breadcrumb form-search">
                <div>
                    <label>所属系统</label>
                    @Html.DropDownList("BelongApplicationType", ConvertToSelector.Instance.EnumTypeConvertToSelectList(typeof(ApplicationType)))
                    <label>菜单</label>
                    @Html.TextBox("roleToPageToActionSearchFormPageName", "", new { @readonly = "readonly", @class = "select-icon", onclick = "showLayerOpen('选择菜单','/PubModelDialog/PageMenuSelector?chkStyle=radio&textid=roleToPageToActionSearchFormPageName&hiddenId=roleToPageToActionSearchFormPageID','420px','90%')" })
                    @Html.Hidden("roleToPageToActionSearchFormPageID")
                    <label>权限</label>
                    @Html.DropDownList("ActionID", ConvertToSelector.Instance.PageActionConvertToSelectList())
                    <label>关键词</label>
                    @Html.TextBox("Keyword", "", new { placeholder = "菜单名等" })
                    <input id="btnReset" class="btn Search-R form-reset" type="button" value="重置">
                    <input id="btnSubmit" class="btn btn-primary Search-R" type="button" value="查询" onclick="search('roleToPageToActionSearchForm', 'roleToPageToAcionTable');">
                </div>
            </form>
            <table id="roleToPageToAcionTable" class="table table-striped table-bordered table-hover">
                <thead>
                    <tr>
                        <th width="50">序号</th>
                        <th width="150">所属系统</th>
                        <th width="150">菜单</th>
                        <th width="150">菜单Url</th>
                        <th width="100">权限</th>
                        <th width="100">权限代码</th>
                        <th width="100">操作</th>
                    </tr>
                </thead>
            </table>
        </div>
    </div>
    <div class="control-group">
        <h4>授权:</h4>
        <div class="controls">
            <form id="pageToActionSarchForm" class="breadcrumb form-search">
                <div>
                    <label>所属系统</label>
                    @Html.DropDownList("BelongApplicationType", ConvertToSelector.Instance.EnumTypeConvertToSelectList(typeof(ApplicationType)))
                    <label>菜单</label>
                    @Html.TextBox("pageToActionSarchFormPageName", "", new { @readonly = "readonly", @class = "select-icon", onclick = "showLayerOpen('选择菜单','/PubModelDialog/PageMenuSelector?chkStyle=radio&textid=pageToActionSarchFormPageName&hiddenId=pageToActionSarchFormPageID','420px','90%')" })
                    @Html.Hidden("pageToActionSarchFormPageID")
                    <label>权限</label>
                    @Html.DropDownList("ActionID", ConvertToSelector.Instance.PageActionConvertToSelectList())
                    <label>关键词</label>
                    @Html.TextBox("Keyword", "", new { placeholder = "菜单名等" })
                    <input id="btnReset" class="btn Search-R form-reset" type="button" value="重置">
                    <input id="btnSubmit" class="btn btn-primary Search-R" type="button" value="查询" onclick="search('pageToActionSarchForm', 'pageToAcionTable');">
                </div>
            </form>
            @using (Html.BeginForm("UpdateRoleToPageToAction", "Role", FormMethod.Post, new { id = "inputFormPageToAction", name = "inputFormPageToAction", enctype = "multipart/form-data" }))
            {
                @Html.Hidden("RoleID", roleID);
                <table id="pageToAcionTable" class="table table-striped table-bordered table-hover">
                    <thead>
                        <tr>
                            <th width="20"><input type="checkbox" id="ckbAll" /></th>
                            <th width="50">序号</th>
                            <th width="150">所属系统</th>
                            <th width="150">菜单</th>
                            <th width="150">菜单Url</th>
                            <th width="100">权限</th>
                            <th width="100">权限代码</th>
                        </tr>
                    </thead>
                </table>
                <div class="align-center margin-t-20">
                    <input id="btnSubmit" class="btn btn-primary Edit-R" type="submit" value="提交">
                </div>
            }
            @section scripts{
                @Scripts.Render("~/bundles/chosen")
                @Styles.Render("~/Content/chosen")
                @Scripts.Render("~/bundles/datatable")
                @Styles.Render("~/Content/datatable")
                <script type="text/javascript">
                    $(function () {
                        var roleToPageToAcionTable = $("#roleToPageToAcionTable").dataTable({
                            fnDrawCallback: function () {
                                ControlPermissionOperate();
                            },
                            "sAjaxSource": "/System/Role/GetRoleToPageToAction?RoleID=@roleID",
                            "sDom": "R<'row'<'col-sm-12'f>r>>>",
                            bSort: false,
                            "iDisplayLength": 10000,
                            aoColumns: [
                                        {
                                            "mData": null,
                                            "bSortable": false,
                                            "fnRender": function (nRow) {
                                                return nRow.iDataRow + 1;
                                            }
                                        },
                                        { "mData": "BelongApplicationTypeDesc" },
                                        { "mData": "PageName" },
                                        { "mData": "PageUrl" },
                                        { "mData": "ActionName" },
                                        { "mData": "ActionCode" },
                                        {
                                            "mData": null, fnRender: function (nRow) {
                                                return "<a class=\"red Delete-R\" href=\"javascript:DeleteObj('" + nRow.aData.ID + "','/System/Role/DeleteRoleToPageToAction','roleToPageToAcionTable')\" title=\"彻底删除\"><i class=\"icon-trash bigger-130\"></i></a>";
                                            }
                                        }
                            ]
                        });

                        var objTable = $("#pageToAcionTable").dataTable({
                            fnDrawCallback: function () {
                                ControlPermissionOperate();
                            },
                            "sAjaxSource": "/System/PageAction/GetPageToAction?ExcludeHaveAuthorize=true&PageToAcionIDs=@pageToActionIDs",
                            "sDom": "R<'row'<'col-sm-12'f>r>>>",
                            "iDisplayLength": 10000,
                            bSort: false,
                            aoColumns: [
                                {
                                    "mData": null,
                                    "bSortable": false,
                                    "fnRender": function (nRow) {
                                        var html = "<input type='hidden' name='model[" + nRow.iDataRow + "].RoleID' id='model_" + nRow.iDataRow + "__RoleID' value='@Request["RoleID"]'>";
                                        html += "<input type='hidden'  name='model[" + nRow.iDataRow + "].ID' id='model_" + nRow.iDataRow + "__ID'  value='" + nRow.aData.ID + "'>";
                                        html += "<input type='checkbox' class='CheckBoxItem' name='model[" + nRow.iDataRow + "].Checked' onclick='checkBox(this)' id='model_" + nRow.iDataRow + "__Checked'>";
                                        return html;
                                    }
                                },
                                {
                                    "mData": null,
                                    "bSortable": false,
                                    "fnRender": function (nRow) {
                                        return nRow.iDataRow + 1;
                                    }
                                },
                                { "mData": "BelongApplicationTypeDesc" },
                                { "mData": "PageName" },
                                { "mData": "PageUrl" },
                                { "mData": "ActionName" },
                                { "mData": "ActionCode" }
                            ]
                        });
                        initCheckBoxItem("pageToAcionTable", "True");
                    });

                    function search(form, table) {
                        /*给查询对象赋值*/
                        if (!form || !table)
                            return;
                        queryParamList.BelongApplicationType = String($("#" + form).find("[id*='BelongApplicationType']").val());
                        queryParamList.PageID = String($("#" + form).find("[id*='" + form + "PageID']").val());
                        queryParamList.ActionID = String($("#" + form).find("[id*='ActionID']").val());
                        queryParamList.Keyword = String($("#" + form).find("[id*='Keyword']").val());
                        $("#" + table).dataTable().fnDraw();
                    }
                </script>
            }
        </div>
    </div>
}
